package com.cheng.io.demo;

import java.io.*;

/**
 * 简单文件复制功能只适用于文本文件，使用FileReader和FileWriter实现
 */
public class FileCopyByReaderWriterStreamImpl {
    public static void main(String[] args) {
        try (
                Reader reader = new FileReader("C:\\Users\\ck\\Desktop\\特性.txt");
                Writer writer = new FileWriter("D:\\code\\java-study\\java-study\\io\\resources\\特性1.txt");
        ) {
            // 一个字符2个字节，1024个字符大小为2kb，512个字符为1kb
            char[] chars = new char[1024 / 2];
            int readCount = 0;
            while ((readCount = reader.read(chars)) != -1) {
                writer.write(chars, 0, readCount);
            }
            writer.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
